﻿/// <reference path="jquery-1.3.2-vsdoc.js">
(function () {
    /*
    *Author Kwan
    *Date 2010-11-22
    *Function jBase class
    */

    //check the class name , it will be replaced when existed
    if (window.Applican) {
        alert('variable jBase has been used,it will be replaced with _Applican!');
        window._Applican = window.Applican;
    }

    //constructor
    window.Applican = function (param) {
        param = param instanceof Object ? param : {};
        this.cfg = param.cfg || {};
    }
    var pt = Applican.prototype;

    pt.successCount = 0;
    pt.failCount = 0;

    pt.AppJob = function (rid, jid) {
        var now = new Date();
        var nowDate = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " " + now.toLocaleTimeString();
        $.ajax({ url: "facade.axd", cache: false, dataType: "json", data: encodeURI("action=Applican&s_method=save&data={\"ResumeID\":\"" + rid + "\",\"JobID\":\"" + jid + "\",\"appDate\":\"" + nowDate + "\",\"State\":\"0\"}"),
            beforeSend: function (x) { x.setRequestHeader("Content-Type", "application/json; charset=utf-8"); },
            complete: function (x, state) {
                var json = eval("(" + x.responseText + ")");
                if (json.success) {
                    //$.ajax({ url: "facade.axd", cache: false, dataType: "json", data: encodeURI("action=EmailSend&s_method=list&id=" + json.data),
                    //beforeSend: function (x) { x.setRequestHeader("Content-Type", "application/json; charset=utf-8"); }
                    //});
                }
            }
        });
    }

    pt.checkJob = function (jid, rid) {
        if (rid == "") {
            if (confirm("您还没有创建简历，现在创建吗？")) { window.location = "/Browser/MyXINJOB.aspx"; }
            return false;
        }
        $.ajax({ url: "facade.axd", cache: false, dataType: "json", data: "action=Applican&s_method=list&query=JobID=" + jid + "%26ResumeID=" + rid + "&limit=2",
            complete: function (x, state) {
                var json = eval("(" + x.responseText + ")");
                if (json.totalCount == 0) { pt.AppJob(rid, jid); pt.successCount++; } else { pt.failCount++; }
                redraw("<li style='text-align:center;'>成功申请 <font color='green'>" + pt.successCount + "</font> 个职位！申请失败 <font color='red'>" + pt.failCount + "</font> 次</li>");
                window.setInterval("FixPosition()", 1);
            }
        });
    }

    pt.appSingleJob = function (j) {
        //if (typeof (uid) == "undefined" || uid == "Error" || uid == "") { alert('请登录后再申请职位！'); window.location = "/Login.aspx?returnUrl=%2fAdvanceSearch.aspx"; }
        jid = j.id.replace('Appli_', '')
        this.checkJob(jid);
    }

    pt.applySelectedJobs = function () {
        var jobArray = [];
        var chxs = $(".table6 :checkbox");
        var j = 0;
        var rid = $(chxs[0]).parent().attr('name');
        for (var i = 0; i < chxs.length; i++) {
            if (chxs[i].checked) {
                jobArray[j] = $(chxs[i]).parent().attr('id');
                j++;
            }
        }
        if (jobArray.length == 0) { alert("请在要选择的职位前打勾！"); return; }
        for (var k = 0; k < jobArray.length; k++) {
            app.checkJob(jobArray[k], rid);
        }
    }

    pt.favJob = function (jid) {
        $.ajax({ url: "facade.axd", cache: false, dataType: "json", data: "action=FavJob&s_method=list&query=JID=" + jid,
            complete: function (x, state) {
                var json = eval("(" + x.responseText + ")");
                if (json.totalCount == 0) {
                    $.ajax({ url: "facade.axd", data: encodeURI("action=FavJob&s_method=save&data={\"JID\":\"" + jid + "\"}") });
                    pt.successCount++;
                }
                else { pt.failCount++; }
                redraw("<li style='text-align:center;'>成功收藏 <font color='green'>" + pt.successCount + "</font> 个职位！收藏失败 <font color='red'>" + pt.failCount + "</font> 次</li>");
                window.setInterval("FixPosition()", 1);
            }
        });
    }

})();

window.app = new Applican();
window._ = app._;